package com.djsearch.widget;



import com.djsearch.R;
import com.djsearch.ui.HelpActivity;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.sax.StartElementListener;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;

public class MyDialog extends Dialog{
    private SharedPreferences preferences;
    private MyDialog dialog;
    private Context mContext;
	public MyDialog(Context context,SharedPreferences preferences) {
		super(context);
		mContext = context;
		this.preferences = preferences;
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.mydialog_layout);
		final CheckBox checkBox = (CheckBox)findViewById(R.id.ischeck);
		checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				// TODO Auto-generated method stub
				if (isChecked) {
					checkBox.setButtonDrawable(R.drawable.checkbox_selected);
					SharedPreferences.Editor editor = preferences.edit();
					editor.putInt("isNotPromtAgain", 0).commit();
					
				} else {
					checkBox.setButtonDrawable(R.drawable.checkbox_normal);
					SharedPreferences.Editor editor = preferences.edit();
					editor.putInt("isNotPromtAgain", 1).commit();
				}
			}
		});
		ImageView imgView = (ImageView)findViewById(R.id.dialogCha);
		imgView.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (dialog != null && dialog.isShowing()) {
					dialog.cancel();
				}
			}
		});
		Button lookBtn = (Button)findViewById(R.id.lookBtn);
		lookBtn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(mContext,HelpActivity.class);
				mContext.startActivity(intent);
				((Activity) mContext).overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
			}
		});
	}

	
	public void setDialog(MyDialog dialog){
		this.dialog = dialog;
	}
	
}
